package com.dews.web.controller.train;

import com.dews.common.annotation.Log;
import com.dews.common.core.controller.BaseController;
import com.dews.common.core.domain.BaseResponse;
import com.dews.common.core.domain.TreeSelect;
import com.dews.common.core.page.TableDataInfo;
import com.dews.common.enums.BusinessType;
import com.dews.common.utils.valid.AddGroup;
import com.dews.common.utils.valid.UpdateGroup;
import com.dews.train.domain.dto.TrainingProgramDTO;
import com.dews.train.domain.dto.TrainingProgramQueryDTO;
import com.dews.train.service.ITrainingProgramService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 专业培养方案Controller
 * 
 * @author qingfeng
 * @date 2024-11-30
 */
@RestController
@Validated
@RequestMapping("/train/trainingProgram")
public class TrainingProgramController extends BaseController {

    private ITrainingProgramService trainingProgramService;

    @Autowired
    public TrainingProgramController(ITrainingProgramService trainingProgramService) {
        this.trainingProgramService = trainingProgramService;
    }

    /**
     * 查询专业培养方案列表
     */
    @PreAuthorize("@ss.hasPermi('train:trainingProgram:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingProgramQueryDTO trainingProgramQueryDTO) {
        return trainingProgramService.selectTrainingProgramList(trainingProgramQueryDTO);
    }

    /**
     * 新增专业培养方案
     */
    @PreAuthorize("@ss.hasPermi('train:trainingProgram:add')")
    @Log(title = "专业培养方案", businessType = BusinessType.INSERT)
    @PostMapping
    public BaseResponse add(@RequestBody @Validated(AddGroup.class) TrainingProgramDTO trainingProgramDTO) {
        return toAjax(trainingProgramService.insertTrainingProgram(trainingProgramDTO));
    }


    /**
     * 修改专业培养方案
     */
    @PreAuthorize("@ss.hasPermi('train:trainingProgram:edit')")
    @Log(title = "专业培养方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public BaseResponse edit(@RequestBody @Validated(UpdateGroup.class) TrainingProgramDTO trainingProgramDTO) {
        return toAjax(trainingProgramService.updateTrainingProgram(trainingProgramDTO));
    }


    /**
     * 获取专业培养方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('train:trainingProgram:query')")
    @GetMapping(value = "/{id}")
    public BaseResponse getInfo(@PathVariable("id") Integer id) {
        return success(trainingProgramService.selectTrainingProgramById(id));
    }

    /**
     * 删除专业培养方案
     */
    @PreAuthorize("@ss.hasPermi('train:trainingProgram:remove')")
    @Log(title = "专业培养方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public BaseResponse remove(@PathVariable List<Integer> ids) {
        return toAjax(trainingProgramService.deleteTrainingProgramByIds(ids));
    }

    /**
     * 构建专业方案树
     */
    @GetMapping("/tree")
    public BaseResponse<List<TreeSelect>> getTrainingProgramTree() {
        return success(trainingProgramService.getTrainingProgramTree());
    }
}
